
package treeHoleUI;


import treeHoleDAO.AccountInformationIMPH;
import treeHoleSERVICE.RegisterIMPH;
import treeHoleSERVICE.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @program:IntelliJ IDEA
 * @Description: 注册界面
 * @author:Mr.CheCheHuiBujianO
 * @data: 2022/6/16 10:27
 */

//  47  53,54,55写入
public class RegistrationPage extends JFrame {


    public RegistrationPage() {
        initComponents();
    }

    private void button1(ActionEvent e) {
        // TODO add your code here
        // 获取用户输入的数据
        String userName = textField1.getText();
        String passWord = textField2.getText();
        String RepassWord = textField3.getText();

        RegisterIMPH registerIMPH= new RegisterIMPH();
        int result = 0;
        int click = JOptionPane.showConfirmDialog(this, "确定提交吗？", "提交提示", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
        if (click == JOptionPane.YES_OPTION){
            result = registerIMPH.register(passWord, RepassWord, userName);
        }
        if(result > 0){
            try {
                JOptionPane.showMessageDialog(this,"注册成功，账号为"+result,"tips",JOptionPane.INFORMATION_MESSAGE);

                LoginInterface loginInterface = new LoginInterface();//.logininterface();         //返回登录页面
                loginInterface.setVisible(true);
                // 将我们账号密码加入我们的txt文件
                AccountInformationIMPH accountInformationIMPH = new AccountInformationIMPH();
                accountInformationIMPH.writeAccountInformation(userName,result,passWord);
                dispose();                    //注册页面关闭
            } catch (Exception ex) {
                ex.printStackTrace();
            } }
        else {
            // JOptionPane pane = new JOptionPane();
            JOptionPane.showMessageDialog(this,"注册失败","警告",JOptionPane.ERROR_MESSAGE);
        }
    }
    private void button2(ActionEvent e) {
        // TODO add your code here
        try{
            LoginInterface loginInterface = new LoginInterface();//.logininterface();         //返回登录页面
            dispose();          //注册页面关闭
            loginInterface.setVisible(true);
        }
        catch (Exception ex){
            ex.printStackTrace();
        }

    }



    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panel1 = new JPanel();
        label1 = new JLabel();
        panel2 = new JPanel();
        label2 = new JLabel();
        textField1 = new JTextField();
        panel3 = new JPanel();
        label3 = new JLabel();
        textField2 = new JTextField();
        panel4 = new JPanel();
        label4 = new JLabel();
        textField3 = new JTextField();
        panel5 = new JPanel();
        button1 = new JButton();
        panel6 = new JPanel();
        button2 = new JButton();

        Dimension dim = new Dimension(400,35);
        textField1.setPreferredSize(dim);
        textField2.setPreferredSize(dim);
        textField3.setPreferredSize(dim);
        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new GridLayout(6, 2));

        //======== panel1 ========
        {
            panel1.setLayout(new FlowLayout());

            //---- label1 ----
            label1.setText("\u6ce8\u518c\u9875\u9762");
            label1.setHorizontalAlignment(SwingConstants.CENTER);
            panel1.add(label1);
        }
        contentPane.add(panel1);

        //======== panel2 ========
        {
            panel2.setLayout(new FlowLayout());

            //---- label2 ----
            label2.setText("\u65b0\u5efa\u7528\u6237\u540d");
            panel2.add(label2);
            panel2.add(textField1);
        }
        contentPane.add(panel2);

        //======== panel3 ========
        {
            panel3.setLayout(new FlowLayout());

            //---- label3 ----
            label3.setText("\u65b0\u5efa\u5bc6\u7801   ");
            panel3.add(label3);
            panel3.add(textField2);
        }
        contentPane.add(panel3);

        //======== panel4 ========
        {
            panel4.setLayout(new FlowLayout());

            //---- label4 ----
            label4.setText("\u786e\u8ba4\u5bc6\u7801   ");
            panel4.add(label4);
            panel4.add(textField3);
        }
        contentPane.add(panel4);

        //======== panel5 ========
        {
            panel5.setLayout(new FlowLayout());

            //---- button1 ----
            button1.setText("\u6ce8\u518c");
            button1.addActionListener(e -> button1(e));
            panel5.add(button1);
        }
        contentPane.add(panel5);

        //======== panel6 ========
        {
            panel6.setLayout(new FlowLayout());

            //---- button2 ----
            button2.setText("\u8fd4\u56de");
            button2.addActionListener(e -> button2(e));
            panel6.add(button2);
        }
        contentPane.add(panel6);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }


    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JLabel label1;
    private JPanel panel2;
    private JLabel label2;
    private JTextField textField1;
    private JPanel panel3;
    private JLabel label3;
    private JTextField textField2;
    private JPanel panel4;
    private JLabel label4;
    private JTextField textField3;
    private JPanel panel5;
    private JButton button1;
    private JPanel panel6;
    private JButton button2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables


}

